package com.kedacom.demo.modb.apdbproxy.handler;

import javax.annotation.Resource;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.kedacom.demo.modb.ap.dao.APJdbcDaoSupport;
import com.kedacom.demo.modb.rabbitmq.message.ModbMessage;
import com.kedacom.demo.modb.rabbitmq.message.UpdateAccountSqlAndEventMessage;

/**
 * {@link ModbMessage}消息处理类
 * @author luocanfeng
 * @date 2013-1-11
 */
@Component("modbMessageHandler")
public class ModbMessageHandler {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Resource
	private APJdbcDaoSupport apJdbcDaoSupport;

	public void handleMessage(UpdateAccountSqlAndEventMessage message) {
		logger.debug("Received: {}", ToStringBuilder.reflectionToString(message, ToStringStyle.SHORT_PREFIX_STYLE));

		apJdbcDaoSupport.getJdbcTemplate().update(message.getSql(), message.getSqlArgs());
		logger.debug("Executed sql: \'{}\' with arguments \'{}\'", message.getSql(),
				ToStringBuilder.reflectionToString(message.getSqlArgs(), ToStringStyle.SHORT_PREFIX_STYLE));
	}

}
